<div class="layui-fluid layui-anim zzdz-anim" id="zzdz-${className?uncap_first}" lay-title="${tableComment}管理">
    <div class="layui-row zzdz-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body zzdz-table-full">
                    <form class="layui-form layui-table-form" lay-filter="${className?uncap_first}-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <#if columns??>
                                        <#list columns as column>
                                           <#if column.isKey = false>
                                               <#if (column.type = 'varchar' || column.type = 'text' || column.type = 'uniqueidentifier'
                                               || column.type = 'varchar2' || column.type = 'nvarchar' || column.type = 'VARCHAR2'
                                               || column.type = 'VARCHAR'|| column.type = 'CLOB' || column.type = 'char')>
                                                   <div class="layui-inline">
                                                       <label class="layui-form-label layui-form-label-sm"> ${column.remark}</label>
                                                       <div class="layui-input-inline">
                                                           <input type="text" name="${column.field?uncap_first}" autocomplete="off" class="layui-input">
                                                       </div>
                                                   </div>
                                               </#if>
                                            </#if>
                                        </#list>
                                    </#if>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary zzdz-button-blue-plain table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary zzdz-button-green-plain table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
                                     shiro:hasAnyPermissions="${className?uncap_first}:add,${className?uncap_first}:update,${className?uncap_first}:export">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="${className?uncap_first}Table" lay-data="{id: '${className?uncap_first}Table'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="${className?uncap_first}-option">
    <span shiro:lacksPermission="${className?uncap_first}:list,${className?uncap_first}:update,${className?uncap_first}:delete">
        <span class="layui-badge-dot zzdz-bg-orange"></span> 无权限
    </span>
    <a lay-event="detail" shiro:hasPermission="${className?uncap_first}:list"><i
                class="layui-icon zzdz-edit-area zzdz-green">&#xe7a5;</i></a>
    <a lay-event="edit" shiro:hasPermission="${className?uncap_first}:update"><i
                class="layui-icon zzdz-edit-area zzdz-blue">&#xe7a4;</i></a>
    <a lay-event="del" shiro:hasPermission="${className?uncap_first}:delete"><i class="layui-icon zzdz-edit-area zzdz-red">&#xe7f9;</i></a>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'zzdz'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            zzdz = layui.zzdz,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#zzdz-${className?uncap_first}'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns,
            createTimeFrom,
            createTimeTo;

        form.render();

        initTable();

        laydate.render({
            elem: '#${className?uncap_first}-createTime',
            range: true,
            trigger: 'click'
        });

        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                var checkStatus = table.checkStatus('${className?uncap_first}Table');
                if (name === 'add') {
                    zzdz.modal.open('新增${tableComment}', '${className?uncap_first}/add', {
                        btn: ['提交', '重置'],
                        area: $(window).width() <= 750 ? '95%' : '660px',
                        yes: function (index, layero) {
                            $('#${className?uncap_first}-add').find('#submit').trigger('click');
                        },
                        btn2: function () {
                            $('#${className?uncap_first}-add').find('#reset').trigger('click');
                            return false;
                        }
                    });
                }
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        zzdz.alert.warn('请选择需要删除的${tableComment}');
                    } else {
                        zzdz.modal.confirm('删除${tableComment}', '确定删除该${tableComment}？', function () {
                            var ${className?uncap_first}Ids = [];
                            layui.each(checkStatus.data, function (key, item) {
                                ${className?uncap_first}Ids.push(item.id)
                            });
                            delete${className}s(${className?uncap_first}Ids.join(','));
                        });
                    }
                }
                if (name === 'export') {
                    var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
                    params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
                    params.pageNum = $view.find(".layui-laypage-em").next().html();
                    zzdz.download(ctx + '${className?uncap_first}/excel', params, '${tableComment}信息表.xlsx');
                }
            },
            options: [{
                name: 'add',
                title: '新增${tableComment}',
                perms: '${className?uncap_first}:add'
            }, {
                name: 'delete',
                title: '删除${tableComment}',
                perms: '${className?uncap_first}:delete'
            }, {
                name: 'export',
                title: '导出Excel',
                perms: '${className?uncap_first}:export'
            }]
        });

        table.on('tool(${className?uncap_first}Table)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                zzdz.modal.view('${tableComment}信息', '${className?uncap_first}/view/' + data.id, {
                    area: $(window).width() <= 750 ? '95%' : '660px'
                });
            }
            if (layEvent === 'del') {
                zzdz.modal.confirm('删除${tableComment}', '确定删除该${tableComment}？', function () {
                    delete${className}s(data.id);
                });
            }
            if (layEvent === 'edit') {
                zzdz.modal.open('修改${tableComment}', '${className?uncap_first}/edit/' + data.id, {
                    area: $(window).width() <= 750 ? '95%' : '660px',
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        $('#${className?uncap_first}-update').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });

        table.on('sort(${className?uncap_first}Table)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            createTimeTo = null;
            createTimeFrom = null;
            tableIns.reload({where: getQueryParams(), page: {curr:1} , initSort: sortObject});
        });

        function getQueryParams() {
            <#if columns??>
            <#list columns as column>
            <#if column.isKey = false>
            <#if (column.type = 'varchar' || column.type = 'text' || column.type = 'uniqueidentifier'
                                             || column.type = 'varchar2' || column.type = 'nvarchar' || column.type = 'VARCHAR2'
                                             || column.type = 'VARCHAR'|| column.type = 'CLOB' || column.type = 'char')>
            var ${column.field?uncap_first} = $searchForm.find('input[name="${column.field?uncap_first}"]').val();
            </#if>
            </#if>
            </#list>
            </#if>
            return {
                <#if columns??>
                <#list columns as column>
                <#if column.isKey = false>
                ${column.field?uncap_first}: ${column.field?uncap_first},
                </#if>
                </#list>
                </#if>
                invalidate_ie_cache: new Date()
            };
        }

        function initTable() {
            tableIns = zzdz.table.init({
                elem: $view.find('table'),
                id: '${className?uncap_first}Table',
                url: ctx + '${className?uncap_first}/list',
                cols: [[
                    {type: 'checkbox'},
                    <#if columns??>
                        <#list columns as column>
                        <#if column.isKey = false>
                    {field: '${column.field?uncap_first}', title: '${column.remark}', minWidth: 120},
                        </#if>
                        </#list>
                    </#if>
                    {title: '操作', toolbar: '#${className?uncap_first}-option', minWidth: 140}
                ]]
            });
        }

        /**
         * 删除${tableComment}
         * @param ids
         */
        function delete${className}s(ids) {
            zzdz.get(ctx + '${className?uncap_first}/delete/' + ids, null, function () {
                zzdz.alert.success('删除${tableComment}成功');
                $query.click();
            });
        }
    })
</script>